<div class="layuimini-container layuimini-page-anim" divname="timeGroup-page">
    <div class="layuimini-main">

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="reload"> 刷新 </button>
                <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="btnRecover"> 恢复默认值 </button>
            </div>
        </script>

        <table class="layui-hide" id="timeGroupPageTable" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table', 'miniPage', 'element', 'faceAPI'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;
        var faceAPI = layui.faceAPI;

        table.render({
            elem: '#timeGroupPageTable',
            //**************************异步请求开始***********************
            url: 'api/TimeGroup/GetList',
            method: 'post',
            headers: {
                token: 'sasasas',
                Authorization: "Bearer " + faceAPI.GetJWTToken()
            },//增加Token验证头
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) { //res 即为原始返回的数据
                if (res.errCode == 0) {
                    var data = res.content;
                    var ret = {
                        "code": res.errCode, //解析接口状态
                        "msg": res.error, //解析提示文本
                        "count": data.totalCount, //解析数据长度
                        "data": data.dataList //解析数据列表
                    };
                    return ret;

                } else {
                    /*layer.open({
                        title: '请求错误',
                        content: '(' + res.errCode + ')' + res.error
                    });  */

                    return {
                        "code": 0, //解析接口状态
                        "msg": '', //解析提示文本
                        "count": 0, //解析数据长度
                        "data": [] //解析数据列表
                    };
                }

            },
            //**************************异步请求结束***********************

            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { type: "checkbox", width: 50 },
                { field: 'num', width: 80, title: '组号', sort: true },
                { field: 'week1', title: '星期一', sort: true, templet: function (d) { return formatTimegroup(d.week1); } },
                { field: 'week2', title: '星期二', sort: true, templet: function (d) { return formatTimegroup(d.week2); } },
                { field: 'week3', title: '星期三', sort: true, templet: function (d) { return formatTimegroup(d.week3); } },
                { field: 'week4', title: '星期四', sort: true, templet: function (d) { return formatTimegroup(d.week4); } },
                { field: 'week5', title: '星期五', sort: true, templet: function (d) { return formatTimegroup(d.week5); } },
                { field: 'week6', title: '星期六', sort: true, templet: function (d) { return formatTimegroup(d.week6); } },
                { field: 'week7', title: '星期日', sort: true, templet: function (d) { return formatTimegroup(d.week7); } },
                { title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        function formatTimegroup(d) {
            //debugger;
            return d.replace(/\/00:00--00:00/g, '').replace(/00:00--00:00/g, '');
        };

        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'reload') {   // 监听添加操作
                //执行搜索重载
                table.reload('timeGroupPageTable', {
                    page: {
                        curr: 1
                    }
                }, 'data');
            } else if (obj.event === 'btnRecover') {   // 恢复默认值
                faceAPI.Ajax({
                    type: 'Post',
                    url: '/api/TimeGroup/SetDefault',
                    success: function (result) {
                        if (result.result == false) {
                            layer.alert(result.error, { icon: 2 });
                        }
                        else {
                            table.reload('timeGroupPageTable', {
                                page: {
                                    curr: 1
                                }
                            }, 'data');
                        }

                    }

                });

            }
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {

                var content = miniPage.getHrefContent('page/TimeGroup/edit.html');
                var openWH = miniPage.getOpenWidthHeight();
                faceAPI.TimeGroupEditPage = data;//向layer页面传值，传值主要代码
                faceAPI.TimeGroupEditPageResult = null;
                var index = layer.open({
                    title: '编辑开门时段',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                    end: function (layero, index) {
                        var rst = faceAPI.TimeGroupEditPageResult;

                        if (rst != null && rst.result) {
                            table.reload('timeGroupPageTable', {
                                page: {
                                    curr: 1
                                }
                            }, 'data');
                        };

                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
        });
    });



</script>